Link namespaced crates through root modules#158724
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Link namespaced crates through root modules
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (865ecdf): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesResults (secondary -2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 485.944s -> 487.045s (0.23%) |
|
(I'll continue reviewing tomorrow.) |
|
I don't remember what we decided regarding cases like this // --extern foo::bar=PATH
mod foo {}
let x = foo::bar::something;Should the module |
|
Suppose we do link to the open module from the item module. // --extern foo::bar=PATH
mod foo {
// foo is the current module, so we go through all the 3 scopes in it including the open mod link
// this certainly doesn't look like it should work
let x = bar::something;
}
mod other {
use crate::foo as renamed;
// we go through all the 3 scopes in the module to which `renamed` refers, including the open mod link
// this also doesn't look like it should work
let x = renamed::bar;
} |
|
The problem is that the similar concerns exist if we insert the links only into "crate root" modules, like this PR does. // --extern foo::bar=PATH
extern crate foo;
mod other {
use crate::foo as renamed;
// we go through all the 3 scopes in the module to which `renamed` refers, including the open mod link
// this also doesn't look like it should work
let x = renamed::bar;
}At least the "current module" problem is harder to trigger (but still possible!) // --extern foo::bar=PATH
extern crate self as foo;
// foo is the current module, so we go through all the 3 scopes in it including the open mod link
// this certainly doesn't look like it should work
let x = bar::something; |
|
It's quite clear that the open mod links only need to be considered in the Also, if the links only work in The cases in which the links are followed still need to be restricted somehow, to avoid the cases from #158724 (comment). |
|
The PR misses all the test cases that demonstrate why this feature is tricky to implement.
|
|
This needs design, and I need maybe one full day to try implementing it myself and think about the details, but I don't have much time for this, unfortunately. @TaKO8Ki |
Part 2 of #152299
This is a follow-up to #153312. That PR added support for resolving a namespaced crate when the root is only an open namespace root. This PR handles the case where the root crate is also present.
For example, if rustc is given both:
then
my_api::utils::itemcan now resolve through themy_api::utilscrate when utils is not found in the real my_api crate.The implementation is based on the Scope-based parts of #152299, but adapted to current main after #153312. In particular, this keeps the missing-root/open-module behavior from #153312 and only extracts the existing-root linking piece from the larger prototype.